/**
 * 
 */
package org.vsg.common.web.servlet.view;

import org.springframework.web.servlet.ModelAndView;

/**
 * @author Bill vison
 *
 */
public class ModuleUnifyView implements SaasUnifyView {
	
	public static final String ORGTYPE_ORG = "org";
	
	private static final String ORGTYPE_COM = "com";
	
	private static final String ORGTYPE_net = "net";
	
	
	private String companyCode;
	
	private String applicationCode;
	
	private String module;
	
	private String orgType;

	public ModuleUnifyView(String companyCode ,String applicationCode ,  String module , String orgType) {
		this.companyCode = companyCode;
		this.applicationCode = applicationCode;
		this.module = module;
		this.orgType = orgType;
	}		
	
	public ModuleUnifyView(String companyCode ,String applicationCode ,  String module) {
		this(companyCode , applicationCode , module, ORGTYPE_ORG);
	}
	


	/* (non-Javadoc)
	 * @see org.vsg.common.web.servlet.view.SaasUnifyView#getPrefixContext()
	 */
	@Override
	public ModelAndView getModelAndView(String viewPattern) {
		
		StringBuilder sb = new StringBuilder("/");
		sb.append(orgType).append(".").append(applicationCode)
		.append(".").append(module);
		
		if (!viewPattern.startsWith("/")) {
			sb.append("/");
		}
		sb.append(viewPattern);
		
		ModelAndView modAndView = new ModelAndView();
		modAndView.setViewName( sb.toString());
		
		return modAndView;
	}

}
